package com.web.zsqqimengzhixing.controller;

import com.web.zsqqimengzhixing.pojo.Login;
import com.web.zsqqimengzhixing.pojo.Result;
import com.web.zsqqimengzhixing.service.UserprofileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private UserprofileService userprofileService;

    //获取验证码并且返回验证码
    //TODO:后期需要实现随机生成验证码
    @PostMapping("/mobile")
    public Result login1(@RequestBody Login login) {
        log.info("返回的手机号为 {}", login);
        //随机生成一个6位数的验证码
        String code = "176430";
        return Result.success(code);
    }

    //验证验证码是否正确,正确后检查数据库是否有该用户，没有则添加默认信息
    @PostMapping("/mobile/code")
    public Result login2(@RequestBody Login login) {
        log.info("返回的手机号为 {}", login.getMobile());
        log.info("返回的验证码为 {}", login.getCode());
        if (login.getCode().equals("176430")) {
            userprofileService.login(login.getMobile());
            return Result.success();
        }
        return Result.error("验证码错误");
    }

}